// miniprogram/pages/index/student/show_job/detail_job/detail_job.js
const db = wx.cloud.database()
const _=db.command;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    job: {},
    _id: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      _id: options._id,
      job: JSON.parse(decodeURIComponent(options.job)),

    })
  },
  check: function(event){
    const that = this;
    let tem="";
    wx.requestSubscribeMessage({
      tmplIds: ['iM5myfGg-CJVqdMbdArIBeH1-mrLYlnjspTwLvFtaZo'], 
      success: res=>{
        tem = res['iM5myfGg-CJVqdMbdArIBeH1-mrLYlnjspTwLvFtaZo'];
        if(tem=="accept"){
            wx.showToast({
            title: '已开启',
          })
          that.sendMyResume(event);
        }else{
          wx.showToast({
            title: '已拒绝',
          })
        }
      },
      fail: res=>{
          wx.showToast({
            title: '已拒绝',
          })
      }
    })
  },
  sendMyResume: function(){
    const that=this;
    const job_id=this.data.job._id;
    const stu_id=this.data._id;
   
    const job_name=this.data.job.job_obj.job_name;
    const openid=this.data.job.job_obj.openid;
    db.collection("student").where({
      _id: _.eq(stu_id),
      'student_obj.jobs_id': _.neq(job_id)
    })
    .update({
      data: {
        'student_obj.jobs_id': _.push(job_id)
      }
    })
    .then(res=>{
      wx.cloud.callFunction({
        name: 'notice',
        data: {
          target: openid,
          title: "收到简历",
          content: job_name,
          note:  '无'
        }
      })

      getApp().tos("已投出")
      setTimeout(function(){wx.navigateBack({})},1000)
     
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})